﻿using MengLin.OOP.DesignPattern.IteratorPattern.BuyTicket.Abstract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.IteratorPattern.BuyTicket.Implements
{
    /// <summary>
    /// 具体聚集类
    /// </summary>
    public class ConcreteAggregate : AbstractAggregate
    {
        private IList<object> _items = new List<object>();
        /// <summary>
        /// 创建迭代器
        /// </summary>
        /// <returns></returns>
        public override AbstractIterator CreateIterator()
        {
            return new ConcreteIterator(this);
        }

        /// <summary>
        /// 聚集的总个数
        /// </summary>
        public int Count
        {
            get { return _items.Count; }
        }

        /// <summary>
        /// 索引器访问
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public object this[int index]
        {
            get { return _items[index]; }
            set { _items.Insert(index, value); }
        }
    }
}
